from models.user_model import User  #引入数据模型
from db_config import db


# 数据表操作的类
# 用户数据库操作
class User_Operation():

    def  __init__(self):
        self.__fields__ = ["id", "username", "password", "phone"]
    
    #所有用户查询
    def all_user(self):
        user_list = User.query.all()
        return user_list

    #用户添加
    def commit_user(self, username, password, phone):
        user1 = User(username = username, password = password, phone = phone)
        db.session.add(user1)
        db.session.commit()

    #条件查询 id
    def find_user_id(self, id):
        user_list = User.query.filter_by(id = id)#.first()
        return user_list
    
    #条件查询 username
    def find_user_username(self, username):
        user_list = User.query.filter_by(username = username)#.first()
        return user_list






